<template>

	<view class="homepage" :style="[pdt]">
		<div class="backBox" :style="[backHeight]">
			<span class="backNav" @click="backNav()"><u-icon name="arrow-left" size="18" :bold="true"></u-icon></span>
			<h3 v-if="scrollTop > 100" :style="[backRight]">{{ggDetail.title}}</h3>
		</div>
		<div class="ggxq">
			<div v-if="gjp">
				<u-skeleton :loading="true" :animate="true" rows="7"  rowsHeight="100"></u-skeleton>
			</div>
			<div class="container" v-else>
				<h3>{{ggDetail.title}}</h3>
				<div class="tags"><u-tag :text="ggDetail.xq" size="mini" type="warning"></u-tag></div>
				<div class="summary">
					<h4><span>摘要</span></h4>
					<ul>
						<li v-if="ggDetail.zkrs"><strong>招考人数</strong> {{ggDetail.zkrs}}</li>
						<li><strong>发布时间</strong> {{ggDetail.fbsj}}</li>
						<li v-if="ggDetail.bmsj"><strong>报名时间</strong> {{ggDetail.bmsj}}</li>
					</ul>
				</div>
				<div class="article">
					<u-read-more ref="uReadMore" color="#d9232f">
						<u-parse :content="ggDetail.ggxq" @load="load"></u-parse>
					</u-read-more>
					<u-divider text="扫码加好友，领取职位表" ></u-divider>
					<div class="img"> <image :src="ewm" mode="widthFix" show-menu-by-longpress="true"></image> </div>
				</div>
				<u-divider text="分割线" :dot="true"></u-divider>
				<div class="origin">
					<h5>原文地址，长按可复制</h5>
					<p><text selectable="true">{{ggDetail.oLink}}</text></p>
				</div>
				<u-divider text="THE END"></u-divider>
				<div class="ysxy">
					<p>来源： {{ ggDetail.origin }}</p>
					<p>(内容以官方公告为准，如有侵权，请联系删除)</p>
				</div>
			</div>
		</div>
		
		<share></share>
		<div class="name">{{name}}</div>
	</view>


</template>

<script>
	import { mapActions } from 'vuex';
	import share from '../common/share/index.vue';
	const db = wx.cloud.database()
	export default {
		data() {
			return {
				name: "",
				ewm: "https://www.baixuemianshi.com/zhuanti/images/lynn.jpg",
				ggid: "",
				ggDetail: {},
				pdt: "",
				backHeight: "",
				backRight: "",
				scrollTop: 0,
				gjp: true,
				fSize: {
					"font-size": "20px"
				}
			}
		},
		onShareAppMessage(options) {
			let that = this
			let shareObj = {
			    title: that.ggDetail.title,
			    path: '/pages/ggxq/index?name=' + this.name + '&ggid=' + that.ggid,
			    imageUrl: ''   
			};
			return shareObj
		},
		onShareTimeline(res) {
			let that = this;
			return {
				title: that.ggDetail.title,
				query: "name=" + that.name + '&ggid=' + that.ggid
			};
		},
		onShow() {},
		onPullDownRefresh() {
			console.log('refresh');
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onPageScroll(e) {
			let that = this;
			that.scrollTop = e.scrollTop
		},
		onLoad(options) {
			if (!options) {} else {
				this.name = options.name
				this.ggid = options.ggid
			}
		},
		computed: {
			searchtimes() {
				return this.$store.getters.searchtimes ? this.$store.getters.searchtimes : '';
			},
			userphone() {
				return this.$store.getters.userphone ? this.$store.getters.userphone : '';
			},
			useropenid() {
				return this.$store.getters.useropenid ? this.$store.getters.useropenid : '';
			},
			username() {
				return this.$store.getters.username ? this.$store.getters.username : '';
			},
			loginpage() {
				return this.$store.getters.loginpage ? this.$store.getters.loginpage : '';
			}
		},
		mounted() {
			this.name = this.name ? this.name : this.username;
			this.LogSetName(this.name);
			this.getGgxq()
		},
		watch: {

		},
		created() {
			let that = this;
			let info = wx.getMenuButtonBoundingClientRect();
			that.pdt = {'padding-top': info.top + info.height + 10 + 'px'}
			that.backHeight = {
				'padding-top': info.top + 'px',
				'padding-bottom': '10px',
				'height': info.height + 'px'
			};
			that.backRight = {
				'margin-right': info.width + 30 + 'px'
			}
		},
		methods: {
			...mapActions(['LogSetSearchtimes','LogSetPhone','LogSetOpenid','LogSetName','LogSetPage']),
			getGgxq(){
				let that = this
				uni.request({
					url: 'https://www.baixuemianshi.com/zpgg/gglist/' + that.ggid + '.js',
					method: 'get',
					dataType: 'text',
					data: {
						sstimes: new Date()
					},
					success: function(res) {
						var resjson = JSON.parse(res.data);
						that.ggDetail = resjson
						that.richStyle()
					}
				});
			},
			richStyle(){
				let that = this
				that.ggDetail.ggxq = that.ggDetail.ggxq.replace(/<section/gi,'<p ')
				that.ggDetail.ggxq = that.ggDetail.ggxq.replace(/<img/gi,'<img width="90%" ')
				that.ggDetail.ggxq = that.ggDetail.ggxq.replace(/<\/section/gi,'<\/p')
				that.ggDetail.ggxq = that.ggDetail.ggxq.replace(/<p>/gi,'<p style="margin: 5px 0; text-indent: 2em">')
				that.gjp = false
			},
			load() {
				this.$refs.uReadMore.init();
			},
			checkJumpInfo(e) {
				let that = this;
				let obj = e
				if(!isNaN(e)){
					obj = that.home.swipers[e]
				}
				if (obj.appid) {
					that.changeXcx(obj.appid, obj.path);
				} else if (obj.link) {
					that.changeWeb(obj.link);
				} else if (obj.path) {
					that.changePath(obj.path);
				} else {
					return;
				}
			},
			changePath(path) {
				let that = this;
				if(path == '../sk-tools/zllq/index'){
					uni.switchTab({
						url: path
					})
				}else{
					uni.navigateTo({
						url: path
					});
				}
			},
			changeXcx(appid, path) {
				wx.navigateToMiniProgram({
					appId: appid,
					path: path,
					success(res) {
						console.log(res);
					},
					fail(e) {
						console.log(e);
					}
				});
			},
			changeWeb(webInfo) {
				uni.navigateTo({
					url: '../webview/index?href=' + encodeURIComponent(webInfo)
				});
			},
			sortBy(attr, rev) {
				//第二个参数没有传递 默认升序排列
				if (rev == undefined) {
					rev = 1;
				} else {
					rev = rev ? 1 : -1;
				}
				return function(a, b) {
					a = parseInt(a[attr]);
					b = parseInt(b[attr]);
					if (a < b) {
						return rev * -1;
					}
					if (a > b) {
						return rev * 1;
					}
					return 0;
				};
			},
			prevPage() {
				if (this.page == 1) return;
				this.page--;
			},
			// 下一页
			nextPage() {
				if (this.page == this.maxPage) return;
				this.page++;
			},
			selectPage(index) {
				this.page = index
			},
			checkZt(){
				let that = this
				let item = that.ggDetail
				let sTime = new Date(item.bmsj);
				let eTime = new Date(item.jzsj);
				let nTime = new Date();
				if(sTime > nTime){
					that.ggDetail.bmType = "warning"
					if(that.calHour(sTime - nTime) > 24){
						that.ggDetail.bmText = "暂未开始报名"
					}else{
						that.ggDetail.bmText = "即将开始报名"
					}
				}else if(sTime < nTime && nTime < eTime){
					if(that.calHour(eTime - nTime) < 24){
						that.ggDetail.bmText = "即将截止报名"
						that.ggDetail.bmType = "error"
					}else{
						that.ggDetail.bmText = "正在报名"
						that.ggDetail.bmType = "success"
					}
				}else{
					that.ggDetail.bmText = "报名截止"
					that.ggDetail.bmType = "info"
				}
			},
			checkState(item){
				let that = this
				let sTime = new Date(item.bmsj);
				let eTime = new Date(item.jzsj);
				let nTime = new Date();
				if(sTime > nTime){
					return "warning"
				}else if(sTime < nTime && nTime < eTime){
					return that.calHour(eTime - nTime) < 24 ? "error" : "success"
				}else{
					return "info"
				}
			},
			calHour(num){
				return Math.floor(num/1000/3600)
			},
			backNav(){
				let pages = getCurrentPages();
				if (pages.length == 1) {
					uni.switchTab({ url: '/pages/index/index' });
				} else {
					uni.navigateBack(1);
				}
			},
			copy(text){
				console.log(text)
				uni.setClipboardData({//复制文本
					data: text,
					success: function (res) {
						wx.showToast({
							title: '复制成功',
							icon:"none",
							mask:"true"//是否设置点击蒙版，防止点击穿透
						})
					}
				 })
			},
			imgView(imgUrl) {
				wx.previewImage({
					urls: [imgUrl], //需要预览的图片http链接列表，注意是数组
					current: '', // 当前显示图片的http链接，默认是第一个
					success: function(res) {},
					fail: function(res) {},
					complete: function(res) {}
				});
			}
		},
        components:{
            share
        }
	};
</script>

<style>
	@import url('./index.css');
</style>
